//
//  GFShareSDKAPI.m
//  ModuleA
//
//  Created by 胡林虎 on 2017/8/9.
//  Copyright © 2017年 胡林虎. All rights reserved.
//

#import "GFShareSDKAPI.h"
//腾讯开放平台（对应QQ和QQ空间）SDK头文件
#import <TencentOpenAPI/TencentOAuth.h>
#import <TencentOpenAPI/QQApiInterface.h>
#import "WeiboSDK.h"
#import <ShareSDK/ShareSDK.h>
#import <WXApi.h>

@implementation GFShareSDKAPI
-(void)setShareClick {

    NSLog(@" 调用 分享 API");

    NSString *shareTitle;
    NSString *shareContent;
    id shareImage;
    NSString *jointShareUrl;  // 拼接以后的Url
    SSDKContentType  shareType;

    SSDKPlatformType platform;
    platform = SSDKPlatformSubTypeQQFriend;

    
    //创建分享参数
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    
    if ([@"微博" isEqualToString:@"微博"]) {
        [shareParams SSDKSetupShareParamsByText:[NSString stringWithFormat:@"%@ %@",shareContent,[NSURL URLWithString:jointShareUrl]]
                                         images:shareImage
                                            url:[NSURL URLWithString:jointShareUrl]
                                          title:shareTitle
                                           type:SSDKContentTypeImage];
    }
    else
    {
        [shareParams SSDKSetupShareParamsByText:shareContent
                                         images:shareImage
                                            url:[NSURL URLWithString:jointShareUrl]
                                          title:shareTitle
                                           type:shareType];
    }
    
    //进行分享
    /*
     在sina开放平台中,你的应用程序必须是审核通过的,如果未通过,无法实现自动登录微博分享,会弹出网页需要你手动登录,登录后也不会跳转微博,会直接返回提示你分享成功
     */
    [shareParams SSDKEnableUseClientShare];
    [ShareSDK share:platform //传入分享的平台类型
         parameters:shareParams
     onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
         switch (state) {
             case SSDKResponseStateSuccess:
                 NSLog(@"分享成功!");
                 break;
             case SSDKResponseStateFail:
                 NSLog(@"分享失败%@",error);
                 break;
             case SSDKResponseStateCancel:
                 NSLog(@"分享已取消");
                 break;
             default:
                 break;
         }
     }];


}

@end
